﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PingPongGame
{
    public class UserRacket : GameObject
    {
        public new const string CollisionGroupString = "userRacket";

        public int Width { get; protected set; }
        public int Height { get; protected set; }
        public ConsoleColor color { get; protected set; }

        public UserRacket(Position topLeft, int width, int height, ConsoleColor color)
            : base(topLeft, new char[,] { { '=' } })
        {
            this.Width = width;
            this.body = GetRacketBody(this.Width, this.Height);
           
            Console.ForegroundColor = color;
        }

        public UserRacket(Position topLeft, ConsoleColor color)
            : base(topLeft, new char[,] { { '=' } })
        {
            this.Width =3;
            this.Height = 1;
            this.body = GetRacketBody(this.Width, this.Height);
            Console.ForegroundColor = color;
        }
        public UserRacket(Position topLeft)
            : base(topLeft, new char[,] { { '='} })
        {
            this.Width = 3;
            this.Height = 1;
            this.body = GetRacketBody(this.Width, this.Height);
            Console.ForegroundColor = ConsoleColor.Green;
        }

        char[,] GetRacketBody(int height, int width)
        {
            char[,] body = new char[width, height];

            for (int cols = 0; cols < width; cols++)
            {
                for (int rows = 0; rows < height; rows++)
                {

                    body[cols, rows] = '=';
                }
            }
            return this.body = body;

            
        }
        public char[,] GetRacketBodyReverce()
        {
            int temp = this.Width;
            this.Width = this.Height;
            this.Height = temp;

            char[,] body = new char[Width, Height];

            for (int cols = 0; cols < Width; cols++)
            {
                for (int rows = 0; rows < Height; rows++)
                {

                    body[cols, rows] = '=';
                }
            }
            return this.body=body;
        }

        public void MoveUp()
        {
            if ((this.topLeft.Row - 1) > PingPongMain.WorldRows-23)
            {
                this.topLeft.Row--;
            }
        }

        public void MoveDown()
        {
            if ((this.topLeft.Row +1)<PingPongMain.WorldRows-5)
            {
                this.topLeft.Row++;
            } 
          
            
        }
        public void MoveFront()
        {
            if ((this.topLeft.Col+1)<PingPongMain.WorldCols-4)

            {
            this.topLeft.Col++;
            }
        }

        public void MoveBack()
        {
            if ((this.topLeft.Col - 1) > PingPongMain.WorldCols - 24)
            {
                this.topLeft.Col--;
            }
        }

        public override string GetCollisionGroupString()
        {
            return UserRacket.CollisionGroupString;
        }

        public override bool CanCollideWith(string otherCollisionGroupString)
        {
            //return otherCollisionGroupString == "block" || otherCollisionGroupString == UserRacket.CollisionGroupString || otherCollisionGroupString == "ball";
            return otherCollisionGroupString == "floorBlock" || otherCollisionGroupString == "ball";
        }
        public override void RespondToCollision(CollisionData collisionData)
        {
            if (collisionData.hitObjectsCollisionGroupStrings.Contains("floorBlock"))
            {
                this.topLeft.Row--;
            }
            
        }

        public override void Update()
        {
        }
    }
}
